local ret = {}

local prefix = "packages.lb_kill.pkg."

local packs = {
  "lb1",
  "lb2",
  "lb3",
  "lb4",

  "lb_boss",

  "lb_jiuzuo",

  "lb_kill_derived",
}

for _, pack in ipairs(packs) do
  local pkg = require(prefix .. pack)
  table.insert(ret, pkg)
end

Fk:loadTranslationTable {
  ["lb_kill"] = "LB崩铁杀",
  ["lb"] = "LB崩铁杀",
}


Fk:loadTranslationTable {
  ["lb_hui"] = "毁",
  ["lb_lie"] = "猎",
  ["lb_shi"] = "识",
  ["lb_xie"] = "谐",
  ["lb_xu"] = "虚",
  ["lb_feng"] = "丰",
  ["lb_hu"] = "护",
  ["lb_ex"] = "EX",
  ["lb_yi"] = "忆",

  ["lb_yinni"] = "隐匿",
  --["lb_boss"] = "BOSS",
}


Fk:loadTranslationTable {
  ["#SpiritedSkillDesc"] = "#\"<b>昂扬技</b>\"：昂扬技发动后，技能失效直到满足<b>激昂</b>条件。",

  ["bag_of_tricks"] = "#\"<b>智囊</b>\" ：即【过河拆桥】【无懈可击】【无中生有】。",

  ["#PutCardTop"] = " %card 被置于牌堆顶",
  ["#PutCardBottom"] = " %card 被置于牌堆底",
}


-- 覆写
if not FileIO.pwd():endsWith("packages/freekill-core") then
  --print("cd packages/freekill-core")
  FileIO.cd("packages/freekill-core")
  GameEvent = require "server.gameevent"

  Room = require "lunarltk.server.room"
  FileIO.cd("../..")
else
  Room = require "server.room"
end

--- 为角色设置武将，并从武将池中抽出，若有隐匿技变为隐匿将。注意此时不会进行选择势力，请随后自行处理<br>
--- 自定义隐匿将，登场时机需要自己添加，登场时需要删除隐匿将的技能
---@param player ServerPlayer
---@param general string @ 主将名
---@param deputy? string @ 副将名
---@param broadcast? boolean @ 是否公示，默认否
function Room:prepareGeneral(player, general, deputy, broadcast)
  self:findGeneral(general)
  self:findGeneral(deputy)
  local skills = Fk.generals[general]:getSkillNameList()
  if Fk.generals[deputy] then
    table.insertTable(skills, Fk.generals[deputy]:getSkillNameList())
  end
  if table.find(skills, function(s) return Fk.skills[s]:hasTag(Skill.Hidden) end) then
    self:setPlayerMark(player, "__hidden_general", general)
    if Fk.generals[deputy] then
      self:setPlayerMark(player, "__hidden_deputy", deputy)
      deputy = ""
    end
    --general = "lb__moze_yinni" --有其它的隐匿再改
    for _, name in ipairs(skills) do
      local skill = Fk.skills[name]
      if skill and skill:hasTag(Skill.Hidden) then
        local skel = skill:getSkeleton()
        if skel and skel.HiddenGeneral and Fk.generals[skel.HiddenGeneral] then
          local gen = Fk.generals[general]
          player.room:setPlayerMark(player, "__hidden_record", { hp = gen.hp, maxHp = gen.maxHp })
          player.room:setPlayerMark(player, "HiddenGeneral", skel.name)
          general = skel.HiddenGeneral
          break
        end
      end
    end
  end
  player.general = general
  player.gender = Fk.generals[general].gender
  self:broadcastProperty(player, "gender")
  if Fk.generals[deputy] then
    player.deputyGeneral = deputy
  end
  player.kingdom = Fk.generals[general].kingdom
  for _, property in ipairs({ "general", "deputyGeneral", "kingdom" }) do
    if broadcast then
      self:broadcastProperty(player, property)
    else
      self:notifyProperty(player, player, property)
    end
  end
end

--- 进行待执行的额外回合，致敬传奇角色昔涟
function Room:actExtraTurn()
  repeat
    while #self.extra_turn_list > 0 do
      local data = table.remove(self.extra_turn_list, 1)
      data.who:gainAnExtraTurn(false, data.reason, data.phases, data.extra_data)
    end
    if self:getTag("lb__xianju") then -- 先耦在这里，有空再改
      for _, to in ipairs(self.players) do
        if to:hasSkill("lb__xianju") then
          local xianju = Fk.skills["lb__xianju"] ---@type TriggerSkill
          self:useSkill(to, xianju, function()
            return xianju:use(Util.DummyTable, nil, to, nil)
          end, Util.DummyTable)
        end
      end
    end
  until #self.extra_turn_list == 0
end

local test = Fk.generals["mouxusheng"]
local list = { "lb_hui", "lb_lie", "lb_shi", "lb_xie", "lb_xu", "lb_feng", "lb_hu", "lb_yi", }
--test:addSkills(table.map(list, function (kingdom) return "role_exmode_mingtu__"..kingdom end))

return ret
